/*
 * @Author: mylesshie@gmail.com
 * @Date: 2020-07-04 22:12:56
 * @LastEditors: mylesshie@gmail.com
 * @LastEditTime: 2020-09-12 15:30:33
 * @description:
 */

import { PermissionsAndroid } from 'react-native'

export const requestCameraPermission = async () => {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.CAMERA,
      {
        title: '请求允许使用相机',
        message: '允许此权限以便用户修改和编辑头像',
        buttonNeutral: '稍后询问',
        buttonNegative: '取消',
        buttonPositive: '允许'
      }
    )
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log('相机授权允许')
    } else {
      console.log('相机权限拒绝')
    }
  } catch (err) {
    console.warn(err)
  }
}

export const requestStoragePermission = async () => {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
      {
        title: '请求允许读取相册',
        message: '允许此权限以便用户修改头像时选择相册',
        buttonNeutral: '稍后询问',
        buttonNegative: '取消',
        buttonPositive: '允许'
      }
    )
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log('相册授权允许')
    } else {
      console.log('相册权限拒绝')
    }
  } catch (err) {
    console.warn(err)
  }
}

export const requestLocationPermission = async () => {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      {
        title: '请求允许获取您的位置',
        message: '允许此权限以便参加活动',
        buttonNeutral: '稍后询问',
        buttonNegative: '取消',
        buttonPositive: '允许'
      }
    )
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log('位置授权允许')
    } else {
      console.log('位置权限拒绝')
    }
  } catch (err) {
    console.warn(err)
  }
}
